package com.oa.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.oa.mapper.AttendanceMapper;
import com.oa.pojo.Attendance;
import com.oa.service.AttendanceService;
import com.oa.vo.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class AttendanceServiceImpl implements AttendanceService {

    @Autowired
    private AttendanceMapper attendanceMapper;

    @Override
    public void addAttendance(Attendance attendance) {
        attendanceMapper.addAttendance(attendance);
    }

    @Override
    public void deleteAttendance(Integer attendanceId) {
        attendanceMapper.deleteAttendance(attendanceId);
    }

    @Override
    public void updateAttendance(Attendance attendance) {
        attendanceMapper.updateAttendance(attendance);
    }

    @Override
    public List<Attendance> getAttendanceList() {
        return attendanceMapper.getAttendanceList();
    }

    @Override
    public Page getAttendancePage(Integer pageNo, Integer pageSize) {
        PageHelper.startPage(pageNo,pageSize);
        List<Attendance> attendanceList = attendanceMapper.getAttendanceList();
        Page page = new Page();
        PageInfo<Attendance> pageInfo = new PageInfo<>(attendanceList);
        page.setPageCount(pageInfo.getPages());
        page.setCount(pageInfo.getTotal());
        page.setObject(pageInfo.getList());
        return page;
    }

    @Override
    public Attendance getAttendance(Integer attendanceId) {
        return attendanceMapper.getAttendance(attendanceId);
    }
}
